package dajiang;

/**
 * @author Hang
 * @date 2022/8/14
 * @project AutumnOffer
 * @description
 **/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

class Solution1 {

    /* Write Code Here */
    public boolean containsNearbyDuplic(int[] nums, int k) {
        HashMap<Integer,Integer> res = new HashMap<>();
        for(int i=0;i<nums.length;i++){
            if(res.get(nums[i])!=null&&i-res.get(nums[i])<=k){
                return true;
            }
            res.put(nums[i],i);
        }
        return false;
    }
}

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        boolean res;

        int nums_size = 0;
        nums_size = in.nextInt();
        int[] nums = new int[nums_size];
        for(int nums_i = 0; nums_i < nums_size; nums_i++) {
            nums[nums_i] = in.nextInt();
        }

        if(in.hasNextLine()) {
            in.nextLine();
        }

        int k;
        k = Integer.parseInt(in.nextLine().trim());

        res = new Solution1().containsNearbyDuplic(nums, k);
        System.out.println(res);
    }
}
